<template>
  <div>
    <!-- 其他页面顶部导航 -->
    <!-- 顶部 -->
    <div class="bar" :class="{ active: show }">
      <!-- 导航名称显示 -->
      <div class="left navname" @click="$router.go(-1)">
        <div class="iconfont icon-fanhui-xianxing">
          <em><slot></slot></em>
        </div>
      </div>
      <slot name="gender"></slot>
      <!-- <div class="middle" v-show="!$route.meta.gender">
        <button
          :class="{ active: $store.state.ismale == 'male' }"
          @click="active('male')"
        >
          男生
        </button>
        <button
          :class="{ active: $store.state.ismale == 'female' }"
          @click="active('female')"
        >
          女生
        </button>
      </div> -->
      <div class="right">
        <div class="menu">
          <span
            class="iconfont icon-icon-7"
            @click="toRouter('search', '')"
          ></span>
          <span :class="{ ins: show }" @click="show = !show"></span>
        </div>
      </div>
    </div>
    <div :class="['menB', { show: show }]" ref="menB">
      <div class="ul">
        <li @click="toRouter('index')">
          <i></i>
          <span>首页</span>
        </li>
        <li @click="toRouter('category')">
          <i></i>
          <span>分类</span>
        </li>
        <li @click="toRouter('rank')">
          <i></i>
          <span>排行榜</span>
        </li>
        <li @click="toRouter('free')">
          <i></i>
          <span>免费</span>
        </li>
        <li @click="toRouter('finished')">
          <i></i>
          <span>完本</span>
        </li>
        <li @click="toRouter('user')">
          <i></i>
          <span>账户</span>
        </li>
      </div>
      <div class="bookbtn" @click="toRouter('bookshelf')">我的书架</div>
    </div>
    <!-- 遮罩层 -->
    <div class="mask" v-if="show" @click="show = !show"></div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      show: false, // 顶部菜单显示隐藏
    };
  },
  methods: {
    toRouter(path, params) {
      if (path != this.$route.name) {
        this.$router.push({
          path: `/${path}`,
          query: { ...params },
        });
      }
    },
  },
};
</script>

<style lang="less" scoped>
.white {
  span {
    color: white !important;
    color: white !important;
    &::before {
      border-color: white !important;
    }
    &::after {
      border-color: white !important;
    }
  }
}
// 顶部
.bar {
  height: 0.7rem;
  display: flex;
  justify-content: space-between;
  padding: 0.25rem;
  background-color: transparent;
  &.active {
    background-color: white;
    color: black;
    span {
      color: black !important;
      &::before {
        border-color: black !important;
      }
      &::after {
        border-color: black !important;
      }
    }
  }
  .left {
    width: 2.4rem;
    margin-left: 0.15625rem;
    flex: 1;
    &.init {
      background: url("../../assets/images/logo-qdm.02fc8.svg") no-repeat center;
      background-size: 100%;
    }
    &.navname {
      font-size: 0;
      div {
        height: 100%;
        line-height: 0.7rem;
        font-size: 0.45rem;
        em {
          font-style: normal;
          font-size: 0.38rem;
          margin-left: 0.304375rem;
          vertical-align: top;
          line-height: 0.65rem;
        }
      }
    }
  }
  .middle {
    font-size: 0;
    flex: 2;
    text-align: center;
    button {
      font-size: 0.4rem;
      border: 1px solid #ed424b;
      color: #ed424b;
      background-color: #f6f7f9;
      padding: 0.048125rem 0.3125rem;
      height: 100%;
      &:nth-child(1) {
        border-radius: 4px 0 0 4px;
      }
      &:nth-child(2) {
        border-radius: 0 4px 4px 0;
      }
      &.active {
        background-color: #ed424b;
        color: white;
      }
    }
  }
  .right {
    font-size: 0;
    flex: 0 0 2.28125rem;
    span {
      position: relative;
      font-size: 0.625rem;
      color: #ed424b;
      margin-left: 0.46875rem;
      &:nth-child(2) {
        font-size: 0.5rem;
      }
    }
    .menu {
      height: 100%;
      line-height: 0.65rem;
      span {
        color: #000;
        &:nth-child(1) {
          font-size: 0.525rem;
          margin-left: 0.51875rem;
        }
        &:nth-child(2) {
          top: 0.12rem;
          width: 0.46875rem;
          height: 0.46875rem;
          display: inline-block;
          &::before {
            content: "";
            position: absolute;
            width: 0.4375rem;
            height: 0.099rem;
            border-top: 1px solid black;
            border-bottom: 1px solid black;
            left: 0;
            top: 0.12rem;
            transition: all 0.5s;
          }
          &::after {
            content: "";
            position: absolute;
            width: 0.4375rem;
            border-top: 1px solid black;
            top: 0;
            transition: all 0.2s;
          }
          // 变插动画
          &.ins {
            &::before {
              border-bottom: none;
              transform: rotate(45deg);
              height: 0;
            }
            &::after {
              transform: translateY(0.09rem) rotate(-45deg);
            }
          }
        }
      }
    }
  }
}
.menB {
  position: fixed;
  z-index: 3;
  width: 100%;
  height: 0px;
  background-color: white;
  overflow: hidden;
  padding-bottom: 0;
  transition: height 0.2s;
  &.show {
    height: 6rem;
    padding-bottom: 0.625rem;
    color: black;
    span {
      color: black !important;
    }
  }
  .ul {
    display: flex;
    flex-wrap: wrap;
    li {
      width: 33.33%;
      height: 2.34375rem;
      padding: 0.46875rem 0;
      text-align: center;
      box-sizing: border-box;
      i {
        width: 0.63rem;
        height: 0.63rem;
        display: block;
        margin: 0 auto 0.15625rem;
        background-image: url("../../assets/images/sprite1.png");
        background-size: 2.1rem 2.1rem;
      }
      &:nth-child(1) {
        i {
          background-position: -0.75rem 0;
        }
      }
      &:nth-child(2) {
        i {
          background-position: -1.47rem -0.68rem;
        }
      }
      &:nth-child(4) {
        i {
          background-position: 0px -0.72rem;
        }
      }
      &:nth-child(5) {
        i {
          background-position: -0.02rem -1.47rem;
        }
      }
      &:nth-child(6) {
        i {
          background-position: -1.47rem 0px;
        }
      }
      span {
        font-size: 0.359375rem;
        font-weight: bold;
        vertical-align: top;
      }
    }
  }
  .bookbtn {
    width: 80%;
    height: 0.9375rem;
    background-color: #ed424b;
    color: white;
    line-height: 0.9375rem;
    border-radius: 0.9375rem;
    text-align: center;
    font-size: 0.359375rem;
    margin: 0.3125rem auto 0;
  }
}
.mask {
  position: fixed;
  width: 100%;
  height: 100%;
  background-color: #00000085;
  transition: all 0.2s;
  z-index: 2;
}
</style>